const jwt = require('jsonwebtoken')
const secret = 'kjafhkjsal'
export const addToken = (userId: string) => {
  let data = { userId: userId }
  let obj = {
    'data': data || {}, // 存入token的数据
    'ctime': (new Date()).getTime() // token的创建时间
  }
  return jwt.sign(obj, secret)
}
export const getToken = (token: string | undefined) => {
  try {
    let { data, ctime, expiresIn } = jwt.verify(token, secret)
    return { data, ctime, expiresIn }
  } catch (error) {
    return 'null'
  }
}